home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_priority.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-17  |  8.2 KB  |  233 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28. #include "system_headers.h"
  29.  
  30. static __asm __saveds LONG pri_callfunc( register __a0 struct Hook *hook, register __a1 char **contents, register __a2 struct Object *obj )
  31. {
  32.     struct PriorityWinData *pwd = INST_DATA(OCLASS(obj), obj);
  33.     UBYTE *pristring;
  34.     LONG pri = 0, length;
  35.  
  36.     get(pwd->pwd_PriorityString, MUIA_String_Contents, &pristring);
  37.  
  38.     length = stcd_i(pristring, (int *)&pri);
  39.     if (length == strlen(pristring) && pri >= -128 && pri <= 127) {
  40.         set(pwd->pwd_PrioritySlider, MUIA_Slider_Level, pri);
  41.         set(obj, MUIA_Window_ActiveObject, pwd->pwd_OkButton);
  42.     } else {
  43.         set(obj, MUIA_Window_ActiveObject, pwd->pwd_PriorityString);
  44.     }
  45.  
  46.     return pri;
  47. }
  48.  
  49. MakeHook(pri_callhook, pri_callfunc);
  50.  
  51. static ULONG __saveds mNew( struct IClass *cl,
  52.                             Object *obj,
  53.                             struct opSet *msg )
  54. {
  55.     APTR pritext1, pritext2, pritext3, SL_Priority, okButton, cancelButton;
  56.  
  57.     if (obj = (Object *)DoSuperNew(cl, obj,
  58.         MUIA_Window_ID, MakeID('P','R','I','O'),
  59.         WindowContents, VGroup,
  60.  
  61.             Child, MyVSpace(2),
  62.             Child, pritext1 = MyTextObject(),
  63.             Child, MyVSpace(2),
  64.             Child, SL_Priority = SliderObject,
  65.                 MUIA_Slider_Min, -128,
  66.                 MUIA_Slider_Max, 127,
  67.                 MUIA_Slider_Level, 0,
  68.                 MUIA_FixHeightTxt, " ",
  69.                 MUIA_CycleChain, TRUE,
  70.             End,
  71.             Child, MyVSpace(2),
  72.             Child, HGroup, MUIA_Group_SameWidth, TRUE,
  73.                 Child, HGroup,
  74.                     Child, MyLabel2(txtMinPri),
  75.                     Child, MyTextObject3(MUIX_C "-128"),
  76.                 End,
  77.                 Child, HGroup,
  78.                     Child, MyLabel2(txtMaxPri),
  79.                     Child, MyTextObject3(MUIX_C "127"),
  80.                 End,
  81.                 Child, HGroup,
  82.                     Child, MyLabel2(txtOldPri),
  83.                     Child, pritext2 = MyTextObject(),
  84.                 End,
  85.                 Child, HGroup,
  86.                     Child, MyLabel2(txtNewPri),
  87.                     Child, pritext3 = StringObject,
  88.                         MUIA_String_BufferPos, 1,
  89.                         MUIA_String_Accept , "-0123456879",
  90.                         MUIA_String_Integer, 0,
  91.                         MUIA_String_MaxLen, 5,
  92.                         MUIA_String_Format, MUIV_String_Format_Right,
  93.                         MUIA_CycleChain, TRUE,
  94.                         StringFrame,
  95.                     End,
  96.                 End,
  97.             End,
  98.             Child, MyVSpace(2),
  99.             Child, HGroup, MUIA_Group_SameWidth, TRUE,
  100.                 Child, okButton = MakeButton(txtMUIOk),
  101.                 Child, cancelButton = MakeButton(txtMUICancel),
  102.             End,
  103.         End,
  104.         TAG_MORE, msg->ops_AttrList))
  105.     {
  106.         struct PriorityWinData *pwd = INST_DATA(cl, obj);
  107.  
  108.         pwd->pwd_PriorityText[0] = pritext1;
  109.         pwd->pwd_PriorityText[1] = pritext2;
  110.         pwd->pwd_PriorityString = pritext3;
  111.         pwd->pwd_PrioritySlider = SL_Priority;
  112.         pwd->pwd_OkButton = okButton;
  113.  
  114.         set(obj, MUIA_Window_Title, MyGetWindowTitle(txtPriorityWinTitle, pwd->pwd_Title, sizeof(pwd->pwd_Title)));
  115.         set(obj, MUIA_Window_ActiveObject, pritext3);
  116.  
  117.         DoMethod(AP_Scout,     OM_ADDMEMBER, obj);
  118.         DoMethod(obj,          MUIM_Notify,  MUIA_Window_CloseRequest, TRUE,           MUIV_Notify_Application, 2, MUIM_Application_ReturnID, 1);
  119.         DoMethod(SL_Priority,  MUIM_Notify,  MUIA_Slider_Level,        MUIV_EveryTime, pritext3,                4, MUIM_SetAsString, MUIA_String_Contents, "%ld", MUIV_TriggerValue);
  120.         DoMethod(pritext3,     MUIM_Notify,  MUIA_String_Acknowledge,  MUIV_EveryTime, obj,                     3, MUIM_CallHook, &pri_callhook, MUIV_TriggerValue);
  121.         DoMethod(okButton,     MUIM_Notify,  MUIA_Pressed,             FALSE,          MUIV_Notify_Application, 2, MUIM_Application_ReturnID, 2);
  122.         DoMethod(cancelButton, MUIM_Notify,  MUIA_Pressed,             FALSE,          MUIV_Notify_Application, 2, MUIM_Application_ReturnID, 1);
  123.     }
  124.  
  125.     return (ULONG)obj;
  126. }
  127.  
  128. static ULONG __saveds mDispose( struct IClass *cl,
  129.                                 Object *obj,
  130.                                 struct opSet *msg )
  131. {
  132.     set(obj, MUIA_Window_Open, FALSE);
  133.  
  134.     DoMethod(AP_Scout, OM_REMMEMBER, obj);
  135.  
  136.     return (DoSuperMethodA(cl, obj, msg));
  137. }
  138.  
  139. static ULONG __saveds mSet( struct IClass *cl,
  140.                             Object *obj,
  141.                             Msg msg )
  142. {
  143.     struct PriorityWinData *pwd = INST_DATA(cl, obj);
  144.     struct TagItem *tags, *tag;
  145.  
  146.     for (tags = ((struct opSet *)msg)->ops_AttrList; tag = NextTagItem(&tags); ) {
  147.         switch (tag->ti_Tag) {
  148.             case MUIA_PriorityWin_ObjectName:
  149.                 MySetContents(pwd->pwd_PriorityText[0], msgSelectNewPriority, (UBYTE *)tag->ti_Data);
  150.                 break;
  151.  
  152.             case MUIA_PriorityWin_Priority:
  153.                 set(pwd->pwd_PrioritySlider, MUIA_Slider_Level, tag->ti_Data);
  154.                 MySetContents(pwd->pwd_PriorityText[1], MUIX_C "%4ld", tag->ti_Data);
  155.                 set(pwd->pwd_PriorityString, MUIA_String_Integer, tag->ti_Data);
  156.                 break;
  157.         }
  158.     }
  159.  
  160.     return (DoSuperMethodA(cl,obj,msg));
  161. }
  162.  
  163. static ULONG __saveds mGet( struct IClass *cl,
  164.                             Object *obj,
  165.                             Msg msg )
  166. {
  167.     struct PriorityWinData *pwd = INST_DATA(cl, obj);
  168.     ULONG *store = ((struct opGet *)msg)->opg_Storage;
  169.  
  170.     switch (((struct opGet *)msg)->opg_AttrID) {
  171.         case MUIA_PriorityWin_Priority:
  172.             get(pwd->pwd_PrioritySlider, MUIA_Slider_Level, store);
  173.             return TRUE;
  174.     }
  175.  
  176.     return (DoSuperMethodA(cl,obj,msg));
  177. }
  178.  
  179. static ULONG __saveds mGetPriority( struct IClass *cl,
  180.                                     Object *obj,
  181.                                     Msg msg )
  182. {
  183.     APTR app;
  184.     BOOL done = FALSE;
  185.     ULONG result = 0;
  186.  
  187.     get(obj, MUIA_ApplicationObject, &app);
  188.     set(app, MUIA_Application_Sleep, TRUE);
  189.     set(obj, MUIA_Window_Open, TRUE);
  190.  
  191.     while (!done) {
  192.         ULONG signals;
  193.  
  194.         switch (DoMethod(app, MUIM_Application_NewInput, &signals)) {
  195.             case MUIV_Application_ReturnID_Quit:
  196.             case 1:
  197.                 done = TRUE;
  198.                 result = 0;
  199.                 break;
  200.  
  201.             case 2:
  202.                 done = TRUE;
  203.                 result = 1;
  204.  
  205.             default:
  206.                 break;
  207.         }
  208.  
  209.         if (!done && signals != 0) Wait(signals);
  210.     }
  211.  
  212.     set(obj, MUIA_Window_Open, FALSE);
  213.     set(app, MUIA_Application_Sleep, FALSE);
  214.  
  215.     return result;
  216. }
  217.  
  218. ULONG __asm __saveds PriorityWinDispatcher( register __a0 struct IClass *cl,
  219.                                             register __a2 Object *obj,
  220.                                             register __a1 Msg msg )
  221. {
  222.     switch (msg->MethodID) {
  223.         case OM_NEW:                       return (mNew(cl, obj, (APTR)msg));
  224.         case OM_DISPOSE:                   return (mDispose(cl, obj, (APTR)msg));
  225.         case OM_SET:                       return (mSet(cl, obj, (APTR)msg));
  226.         case OM_GET:                       return (mGet(cl, obj, (APTR)msg));
  227.         case MUIM_PriorityWin_GetPriority: return (mGetPriority(cl, obj, (APTR)msg));
  228.     }
  229.  
  230.     return (DoSuperMethodA(cl, obj, msg));
  231. }
  232.  
  233.